package com.healer.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.healer.dao.SystemLogMapper;
import com.healer.service.SystemLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SystemLogServiceImpl implements SystemLogService {
    @Autowired
    SystemLogMapper systemLogMapper;

    public void setSystemLogMapper(SystemLogMapper systemLogMapper) {
        this.systemLogMapper = systemLogMapper;
    }

    @Override
    public int saveLog(Map map) {
        return systemLogMapper.saveLog(map);
    }

    @Override
    public Map<String,Object> queryLogList(Map map) {
        System.out.println("[debug]==>我进来了");
        //     当前页
        int pageNum=Integer.parseInt(map.get("pageNum").toString());
//      页长
        int pageSize=Integer.parseInt(map.get("pageSize").toString());
        PageHelper.startPage(pageNum,pageSize);
        List<Map<String,Object>> maps = systemLogMapper.queryLogList(map);
        PageInfo pageInfo=new PageInfo(maps);
        long total=pageInfo.getTotal();
        maps.forEach(e-> System.out.println(e.toString()));
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("total",total);
        resultMap.put("rows",maps);
        System.out.println("[debug]==>我出去了");
        return resultMap;
    }

    @Override
    public int deleteLog(String logId) {
        return systemLogMapper.deleteLog(logId);
    }
}
